﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace AIVision.Repository.Migrations
{
    public partial class init20 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Cameras",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: false),
                    HardKey = table.Column<string>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Cameras", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CheckTemplates",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Code = table.Column<string>(type: "TEXT", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: false),
                    IsStart = table.Column<bool>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CheckTemplates", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PLCConfigs",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    IP = table.Column<string>(type: "TEXT", nullable: false),
                    ZhuanTaiRunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    ZhuanTaiInitOffset = table.Column<float>(type: "REAL", nullable: false),
                    ZhuanTaiStep = table.Column<float>(type: "REAL", nullable: false),
                    PPURunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    PPURunPos1 = table.Column<float>(type: "REAL", nullable: false),
                    PPURunPos2 = table.Column<float>(type: "REAL", nullable: false),
                    PPURunPos3 = table.Column<float>(type: "REAL", nullable: false),
                    PPURunPos4 = table.Column<float>(type: "REAL", nullable: false),
                    TuLunRunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    TuLunStep = table.Column<float>(type: "REAL", nullable: false),
                    FeiLiaoRunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    FeiLiaoRunPos1 = table.Column<float>(type: "REAL", nullable: false),
                    FeiLiaoRunPos2 = table.Column<float>(type: "REAL", nullable: false),
                    FeiLiaoRunPos3 = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYRunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYZeroLocation = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYFirstLocation = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYLastLocation = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYStep = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeYCount = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeXRunSpeed = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeXZeroLocation = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeXFirstLocation = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeXStep = table.Column<float>(type: "REAL", nullable: false),
                    ChaHeXCount = table.Column<float>(type: "REAL", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PLCConfigs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CheckStations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Index = table.Column<int>(type: "INTEGER", nullable: false),
                    StationCode = table.Column<string>(type: "TEXT", nullable: true),
                    StationType = table.Column<string>(type: "TEXT", nullable: true),
                    IsSaveOKImage = table.Column<bool>(type: "INTEGER", nullable: false),
                    IsSaveDefectImage = table.Column<bool>(type: "INTEGER", nullable: false),
                    ImageFileSavePath = table.Column<string>(type: "TEXT", nullable: true),
                    ImageCache = table.Column<bool>(type: "INTEGER", nullable: false),
                    HSmartWindowName = table.Column<string>(type: "TEXT", nullable: true),
                    InspectType = table.Column<string>(type: "TEXT", nullable: true),
                    HCFilePath = table.Column<string>(type: "TEXT", nullable: true),
                    DLProcessFilePath = table.Column<string>(type: "TEXT", nullable: true),
                    DLModelFilePath = table.Column<string>(type: "TEXT", nullable: true),
                    DLDevice = table.Column<string>(type: "TEXT", nullable: true),
                    OKScore = table.Column<int>(type: "INTEGER", nullable: true),
                    OutScore = table.Column<int>(type: "INTEGER", nullable: true),
                    CheckTemplateId = table.Column<int>(type: "INTEGER", nullable: false),
                    CameraId = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CheckStations", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CheckStations_Cameras_CameraId",
                        column: x => x.CameraId,
                        principalTable: "Cameras",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CheckStations_CheckTemplates_CheckTemplateId",
                        column: x => x.CheckTemplateId,
                        principalTable: "CheckTemplates",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "DefectItems",
                columns: table => new
                {
                    Id = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    AreaName = table.Column<string>(type: "TEXT", nullable: false),
                    AreaIndex = table.Column<int>(type: "INTEGER", nullable: false),
                    DefectName = table.Column<string>(type: "TEXT", nullable: false),
                    DefectCode = table.Column<string>(type: "TEXT", nullable: false),
                    MinArea = table.Column<int>(type: "INTEGER", nullable: false),
                    MinWidth = table.Column<int>(type: "INTEGER", nullable: false),
                    MinHeight = table.Column<int>(type: "INTEGER", nullable: false),
                    MaxStructFactor = table.Column<int>(type: "INTEGER", nullable: false),
                    CheckStationId = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DefectItems", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DefectItems_CheckStations_CheckStationId",
                        column: x => x.CheckStationId,
                        principalTable: "CheckStations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CheckStations_CameraId",
                table: "CheckStations",
                column: "CameraId");

            migrationBuilder.CreateIndex(
                name: "IX_CheckStations_CheckTemplateId",
                table: "CheckStations",
                column: "CheckTemplateId");

            migrationBuilder.CreateIndex(
                name: "IX_DefectItems_CheckStationId",
                table: "DefectItems",
                column: "CheckStationId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "DefectItems");

            migrationBuilder.DropTable(
                name: "PLCConfigs");

            migrationBuilder.DropTable(
                name: "CheckStations");

            migrationBuilder.DropTable(
                name: "Cameras");

            migrationBuilder.DropTable(
                name: "CheckTemplates");
        }
    }
}
